<?php

function list_replacement(){
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'No Posisi'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Posisi Kosong'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Kandidat Karyawan'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:15%'), 
	);

	$query = "SELECT a.* FROM jabatan a	
		INNER JOIN sk_jabatan b ON b.sk_id=a.sk_id
		WHERE b.active='Y' 
		ORDER BY a.urut" ;
		
	$result = my_query($query);
	$row = array();
	$i = 0;
	while($ey = my_fetch_array($result) ){
		$datas = explode("," , $ey['kebutuhan_tenaga_kerja']);
		$totalgroup=$datas[0]+$datas[1]+$datas[2];
		$tersedia = getshifttersedia( $ey['jabatan_id'] );
		$kosong = ($totalgroup-$tersedia) ;
		$jumlah_kandidat=getjumlahkandidat( $ey['jabatan_id'] );
		if($kosong>0){
			$i++; 
			if($jumlah_kandidat>0){
				$detailproperty = array(
					'href'=>'index.php?com=replacement&task=detail&id='.$ey['jabatan_id'],
					'title'=>'Detail'
				);
				$detail_button = button_icon( 'b_props.png' , $detailproperty  );
			}else{
				$detail_button = button_icon( 'bd_deltbl.png' , ''  );		
			}			
			$row[] = array(
				'no'=>$i,
				'nomor_org'=> $ey['nomor_posisi'],
				'jabatan'=>  $ey['nama_jabatan'] ,
				'kosong'=>$kosong,  
				'Kandidat'=>$jumlah_kandidat,  
				'operasi'=> position_text_align( $detail_button , 'right'), 
			);	
		}	
	}
	$datas = table_rows($row);
	$menuontop = array(
		'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=replacement\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
	);
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return $printmenu.table_builder($header , $datas ,6 , false );;
}

function list_kandidat($jabatan_id){
	$header  = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'), 
		'NIK'=>array('style'=>'border-bottom:2px solid;width10%'),  
		'Karyawan'=>array('style'=>'border-bottom:2px solid;width:30%'),  
		'Nomor Posisi'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Keterangan'=>array('style'=>'border-bottom:2px solid;width:20%'),   
	);
	
	$query = "SELECT a.jabatan_id,b.label FROM jalur_karir_rotasi a
		INNER JOIN jalur_karir_move b ON a.jalur_karir_move_id=b.jalur_karir_move_id 
		WHERE a.new_jabatan_id = {$jabatan_id} ";
	$result = my_query($query);
	$i = 0;
	while($ey = my_fetch_array($result) ){
		$query = "SELECT karyawan_id FROM kekaryawanan 
			WHERE jabatan_id = {$ey['jabatan_id']} ";
		$dres = my_query($query);
		while($dey = my_fetch_array($dres) ){	
			$jabatans = my_get_data_by_id('jabatan','jabatan_id',$ey['jabatan_id']);
			$karyawan_id=$dey['karyawan_id'];
			$karyawan = loaddata_karyawan($karyawan_id);
			$i++;
			$row[] = array(
				'#'=>position_text_align ($i, 'center'),  
				'nik'=>$karyawan['nik'],				
				'karyawan'=>$karyawan['nama_gelar'],
				'no_org'=>$jabatans['nomor_posisi'],	
				'jabat'=>$jabatans['nama_jabatan'], 					
				'ket'=>$ey['label'],    
			);
		}
	}

	$datas = table_rows($row);
	$jabatan = loaddata_jabatan($jabatan_id) ;

	$view .= form_header( "..." , "..."  );
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value="Back" class="main_button" onclick="javascript:location.href=\'index.php?com=replacement\'"/>
	</div></td></tr>'   ; 
	$view .= form_field_display( '<span class="label_form">'.$jabatan['nomor_posisi'] .'</span>'  , "<b>Nomor Posisi</b>"    );  	
	$view .= form_field_display( '<span class="label_form">'.$jabatan['nama_jabatan'].'</span>'   , "<b>Jabatan</b>"    );  
	$view .= form_field_display( '<span class="label_form">'.$jabatan['organisasi_departemen'] .'</span>'  , "<b>Departemen</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$jabatan['organisasi_direktorat'] .'</span>'  , "<b>Direktorat</b>"    ); 
	return  $view. table_builder($header , $datas ,  3 , false );
}

